#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
queue<int> q;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	while (n--) {
		int op; cin >> op;
		if (op == 1) {
			int x; cin >> x;
			q.push(x);
		}else if (op == 2) {
			if (q.empty()) cout << "ERR_CANNOT_POP" << endl;
			else q.pop();
		}else if (op == 3) {
			if (q.empty()) cout << "ERR_CANNOT_QUERY" << endl;
			else cout << q.front() << endl;
		}else cout << q.size() << endl;
	}
	return 0;
}